package com.joker.springboottestdemo.config;


import com.joker.demo.core.config.JobExecutorProperties;
import com.joker.demo.core.executor.impl.JobExecutorSpringbootExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : feixiang.li
 * @since : 2025-07-27 15:33
 */
@Slf4j
@Configuration
public class JobConfig {

    /**
     * 任务执行器端口
     */
    @Value("${job.executor.port}")
    private Integer port;

    /**
     * 调度器地址
     */
    @Value("${job.executor.server-url}")
    private String serverUrl;

    /**
     * 调度器port
     */
    @Value("${job.executor.server-port}")
    private Integer serverPort = 8080;

    /**
     * 访问令牌
     */
    @Value("${job.executor.access-token}")
    private String accessToken = "";

    @Value("${job.executor.group-name}")
    private String groupName = "default";


    @Bean
    JobExecutorSpringbootExecutor jobExecutorSpringbootExecutor() {
        JobExecutorProperties props = new JobExecutorProperties();
        props.setPort(port);
        props.setServerUrl(serverUrl);
        props.setServerPort(serverPort);
        props.setAccessToken(accessToken);
        props.setGroupName(groupName);
        JobExecutorProperties.ThreadPoolMonitorConfig threadPoolMonitorConfig = new JobExecutorProperties.ThreadPoolMonitorConfig();
        props.setThreadPoolMonitor(threadPoolMonitorConfig);
        log.info("springboot-job测试机器配置 init:{}", props);
        return new JobExecutorSpringbootExecutor(props);
    }
}
